(function () {
    window.lib = {};
    window.lib.$ = function () {
        var elements = new Array();
        for (var i = 0; i < arguments.length; i++) {
            var element = arguments[i];
            if (typeof element == 'string') {
                element = document.getElementById(element);
            }
            if (arguments.length == 1) {
                return element;
            }
            elements.push(element);
        }
        return elements;
    }

    window.$CE = function () {
        var tmpTagname = arguments[0];
        if (typeof tmpTagname === 'string') {
            return document.createElement(tmpTagname);
        }
    }

    lib.dom = {};

    window.lib.formatLink = function (arg) {  //format the link  and make the head of the string is "http://".
        var reg = /(http:\/\/|https:\/\/)((\w|=|\?|\.|\/|&|-)+)/g;
        return reg.exec(arg) ? arg : "http://" + arg;
    }

    lib.comm = {};
    lib.comm.sendAndGetData = function (isAsy, url, func) {
        try {
            xmlRequest.open("GET", url, isAsy);
            xmlRequest.onreadystatechange = function () {
                if (xmlRequest.readyState == 4 && xmlRequest.status == 200) {
                    func(xmlRequest.responseText);
                }
            };
            xmlRequest.send();
        }
        catch (e) {
            return false;
        }
    };

    function getEvent() {
        if (document.all !== undefined) {
            return window.event;
        }
        var fun = getEvent.caller;
        while (fun != null) {
            var arg = fun.arguments[0];
            if (arg) {
                if (arg.constructor == Event || arg.constructor == MouseEvent)
                    return arg;
            }
            fun = fun.caller;
        }
        return null;
    }

    window.lib.getEvent = getEvent;

    window.lib.formatEvent = function () {
        // TODO  bug: oEvent is undefined
        var oEvent = window.event ? window.event : arguments[0];
        if (typeof oEvent.charCode == "undefined") {
            oEvent.charCode = (oEvent.type == "keypress") ? oEvent.keyCode : 0;
            oEvent.isChar = (oEvent.charCode > 0);
        }

        if (oEvent.keyCode == undefined) {
            oEvent.keyCode = oEvent.which;
        }

        if (oEvent.srcElement && !oEvent.target) {
            oEvent.eventPhase = 2;
            if (oEvent.pageX == undefined) //get the absolute coordinate of the event.
            {
                if (document.documentElement.scrollLeft != undefined) {
                    oEvent.pageX = oEvent.clientX + document.documentElement.scrollLeft;
                    oEvent.pageY = oEvent.clientY + document.documentElement.scrollTop;
                }
                else {
                    oEvent.pageX = oEvent.clientX + document.body.scrollLeft;
                    oEvent.pageY = oEvent.clientY + document.body.scrollTop;
                }
            }

            if (!oEvent.preventDefault) {
                oEvent.preventDefault = function () {
                    this.returnValue = false;
                };
            }

            if (oEvent.type == "mouseout") {
                oEvent.relatedTarget = oEvent.toElement;
            } else if (oEvent.type == "mouseover") {
                oEvent.relatedTarget = oEvent.fromElement;
            }

            if (!oEvent.stopPropagation) {
                oEvent.stopPropagation = function () {
                    this.cancelBubble = true;
                };
            }

            oEvent.target = oEvent.srcElement ? oEvent.srcElement : oEvent.target;
            oEvent.time = (new Date).getTime();
            oEvent.getEvent = function () {
                if (window.event) {
                    return window.event;
                } else {
                    return arguments[0];
                }
            }

            //在 Firefox 里面
            //没有按键动作的时候 event.button = 0
            //左键是 event.button = 0
            //中键是 event.button = 1
            //右键是 event.button = 2
            if (Sys.ie) {
                switch (oEvent.button) {
                    case 1:
                        //oEvent.setAttribute("newButton", 0);
                        oEvent.newButton = 0;
                        break;
                    case 4:
                        //oEvent.setAttribute("newButton", 1);
                        oEvent.newButton = 1;
                        break;
                    default:
                        //oEvent.setAttribute("newButton", oEvent.button);
                        oEvent.newButton = oEvent.button;
                        break;
                }
            }
        }
        if (Sys.firefox) {
            //oEvent.setAttribute("newButton", oEvent.button);
            oEvent.newButton = oEvent.button;
        }
        return oEvent;
    };

    window.lib.Time = (function () {
        var beginTime;
        function constructor() {
            return (new Date()).getTime().toString();
        }
        return {
            getID: function () {
                if (!beginTime) {
                    beginTime = constructor();
                }
                else {
                    var tmp = (new Date()).getTime().toString();
                    var dis = Number(tmp.substring(5, tmp.length)) - Number(beginTime.substring(5, beginTime.length));
                    if (dis > 1000) {//如果时间过期
                        beginTime = constructor();
                    }
                    beginTime = beginTime.substring(0, 5) + (Number(beginTime.substring(5, tmp.length)) + 1).toString();
                }
                return beginTime;
            }
        }
    })();

    lib.setInterval = (function () {
        var initialNum;
        function constructor() {
            return 0;
        }
        return {
            getValue: function (num) {//设置时间间隔，每秒运行num次。
                if (initialNum == undefined) {
                    initialNum = constructor();
                }
                else {
                    initialNum++;
                }
                if (initialNum % parseInt(1000 / num) == 0) return true;
                return false;
            }
        }
    })();

    lib.getScrollTopLeft = function () {
        // 定义鼠标在视窗中的位置
        var point = {
            scrollLeft: 0,
            scrollTop: 0
        };

        // 如果浏览器支持 pageYOffset, 通过 pageXOffset 和 pageYOffset 获取页面和视窗之间的距离
        if (typeof window.pageYOffset != 'undefined') {
            point.scrollLeft = window.pageXOffset;
            point.scrollTop = window.pageYOffset;
        }
        // 如果浏览器支持 compatMode, 并且指定了 DOCTYPE, 通过 documentElement 获取滚动距离作为页面和视窗间的距离
        // IE 中, 当页面指定 DOCTYPE, compatMode 的值是 CSS1Compat, 否则 compatMode 的值是 BackCompat
        else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
            point.scrollLeft = document.documentElement.scrollLeft;
            point.scrollTop = document.documentElement.scrollTop;
        }
        // 如果浏览器支持 document.body, 可以通过 document.body 来获取滚动高度
        else if (typeof document.body != 'undefined') {
            point.scrollLeft = document.body.scrollLeft;
            point.scrollTop = document.body.scrollTop;
        }
        return point;
    };

    lib.loginModule = function () {
        var loginHtml = "<div id='light' class='loginBox'>";
        loginHtml = loginHtml + "<div id='tabsHead'><span class='curtab tabs' id='tabs1' onclick='javascript:showTab(\"tabs1\",\"tabContent1\")'>" + lan["signOn"] + "</span>";
        loginHtml = loginHtml + "<span class='tabs' id='tabs2' onclick='javascript:showTab(\"tabs2\",\"tabContent2\")'>" + lan["loginIn"] + "</span></div>";
        // loginHtml = loginHtml + "<span style='float:right;border:0px;' onclick='javascript:g.lightOn.cancle()'></span></div>";
        loginHtml = loginHtml + "<div id='tabContent1' class='content_sign'>"; //我很生气，我很惊喜，原来是这没有white导致透明!
        var preUsername;
        if (g.user.username != U) {
            preUsername = '';
        } else if (lib.cookie.get("lastUsername") != U) {
            preUsername = lib.cookie.get("lastUsername");
        } else {
            preUsername = g.DomainSuf;
        }
        loginHtml = loginHtml + "<table>"
            + "<tr><td><span class='icon-close' onclick='javascript:g.lightOn.cancle()'>×</span></td></tr>"
            + "<tr class='userInput'><td><label>" + lan["username"] + "</label><input required id='UsernameID' type='text' value='" + preUsername + "'/><i class='iconfont icon-user'></i></td></tr>";
        loginHtml = loginHtml + "<tr class='userInput'><td><label>" + lan["password"] + "</label><input required id='PasswordID' type='password'/><i class='iconfont icon-mima'></i></td></tr>";
        loginHtml = loginHtml + "<tr><td><span id='tipLogin' class='classtip'></span></td></tr>";
        //zmc:添加“找回密码”连接.
        loginHtml = loginHtml + "<tr><td><a class='forgetPsw' href='FindPass.aspx' target='_blank'>" + lan["ForgetPass"] + "</a></td></tr>";
        loginHtml = loginHtml + "<tr class='controlBtn'><td><input onclick='g.logIn()' value='" + lan["submit"] + "' type='button' /></td></tr></table></div>";
        // 注册
        loginHtml = loginHtml + "<div id='tabContent2' class='content_sign content_hide'>"
            + "<table><tr><td><span class='icon-close' onclick='javascript:g.lightOn.cancle()'>×</span></td></tr>"
            + "<tr class='userInput'><td><label>" + lan["username"] + "</label><input id='regUsername' type='text' required onblur='g.checkUser(this.value)' maxlength='15'/></td></tr>"
            + " <tr><td> <span id='tipUsername' class='classtip'></span></td></tr>"
            + "<tr><td><span style='color: gray; font-size: 12px;margin-left: 44px;'>" + lan["24"] + "</span></td></tr>"
            + "<tr class='userInput'><td><label>" + lan["email"] + "</label><input id='regEmail' type='text' onblur='g.checkMail(this.value);'/></td></tr>"
            + "<tr><td><span id='tipMail' class='classtip'></span></td></tr>"
            + "<tr class='userInput'><td><label>" + lan["password"] + "</label><input id='regPassword' type='password' onblur='g.checkPassw(this.value);'/></td></tr>"
            + "<tr><td><span id='tipPassword' class='classtip'></span></td></tr>"
            + "<tr class='userInput'><td><label>" + lan["repassword"] + "</label><input id='regRepassword' type='password' onblur='g.checkPassw2(this.value)'/></td></tr>"
            + "<tr><td><span id='tipRepassword' class='classtip'></span></td></tr>"
            + "<tr class='controlBtn'><td><input style='' onclick='g.registerUser()' value='" + lan["submit"] + "' type='button' /></td></tr></table></div>"
// <td><input style='background-color:#7D7D2D;padding:0px 20px 0px 20px;' value='" + lan["cancel"] + "' type='button'/></td>
        return loginHtml;
    };

    lib.transparentDiv = (function () {
        var uniqueTransparentDiv;
        function constructor() {
            uniqueTransparentDiv = $CE("div"); //创建一个透明div
            uniqueTransparentDiv.id = "transparentDiv"; //设置id
            lib.dom.setStyle(uniqueTransparentDiv, "position:absolute;z-Index:8;top:0; left:0;background-color:black;opacity:.50;moz-opacity:0.5;filter:alpha(opacity=30);");
            uniqueTransparentDiv.style.width = (document.body.scrollWidth) + "px"; //设置div宽度为水平滚动条的宽度
            // uniqueTransparentDiv.style.width = (document.body.scrollWidth + 30) + "px"; //设置div宽度为水平滚动条的宽度
            //设置高度为竖直滚动条高度
            uniqueTransparentDiv.style.height = (document.body.offsetHeight > document.body.scrollHeight) ? '100%' : (document.body.scrollHeight + "px");
            return uniqueTransparentDiv;
        }
        return {
            getInstance: function () {
                if (!uniqueTransparentDiv) {
                    uniqueTransparentDiv = constructor();
                }
                return uniqueTransparentDiv;
            },
            on: function () {
                document.body.appendChild(lib.transparentDiv.getInstance());
            },
            off: function () {
                var tmp = lib.transparentDiv.getInstance();
                if (tmp.parentNode != null)
                    tmp.parentNode.removeChild(tmp);
            }
        }
    })();


    lib.parseUri = function (str) {
        if (!lib.parseUri || !lib.parseUri.options) {
            lib.parseUri.options = {
                strictMode: false,
                key: ["source", "protocol", "authority", "userInfo", "user", "password", "host", "port", "relative", "path", "directory", "file", "query", "anchor"],
                q: {
                    name: "queryKey",
                    parser: /(?:^|&)([^&=]*)=?([^&]*)/g
                },
                parser: {
                    strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
                    loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
                }
            };
        }

        if (!str) {
            return '';
        }

        var o = lib.parseUri.options,
            m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
            uri = {},
            i = 14;

        while (i--) uri[o.key[i]] = m[i] || "";

        uri[o.q.name] = {};
        uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
            if ($1) uri[o.q.name][$1] = $2;
        });

        return uri;
    };


    //+--------------------operate cookies-----------------------------------------
    lib.cookie = {};
    lib.cookie.set = function (name, value, expires, path) {
        var expDays = expires * 24 * 60 * 60 * 1000;
        var expDate = new Date();
        expDate.setTime(expDate.getTime() + expDays);
        var expString = ((expires == null) ? "" : (";expires=" + expDate.toGMTString()));
        var pathString = ((path == null) ? "" : (";path=" + path + ";"));
        var domainString = "domain=" + g.mainDomain + ";";
        var tmp = name + "=";
        tmp = tmp + escape(value);
        tmp = tmp + expString;
        tmp = tmp + pathString;
        tmp = tmp + domainString;
        document.cookie = tmp;
    }

    lib.cookie.get = function (name) {
        var result = null;
        var myCookie = document.cookie + ";";
        var searchName = name + "=";
        var startOfCookie = myCookie.indexOf(searchName);
        var endOfCookie;
        if (startOfCookie != -1) {
            startOfCookie += searchName.length;
            endOfCookie = myCookie.indexOf(";", startOfCookie);
            result = unescape(myCookie.substring(startOfCookie, endOfCookie));
        }
        return result;
    }


    lib.cookie.clear = function (name, path) {
        var ThreeDays = 3 * 24 * 60 * 60 * 1000;
        var expDate = new Date();
        expDate.setTime(expDate.getTime() - ThreeDays);
        var pathString = ((path == null) ? "" : (";path=" + path + ";"));
        var domainString = "domain=" + g.mainDomain + ";";
        var tmp = name + "=;";
        tmp = tmp + "expires=" + expDate.toGMTString();
        tmp = tmp + pathString;
        tmp = tmp + domainString;
        document.cookie = tmp;
    }
    //*------------------------------------------------------------------------

    lib.dom.setStyle = function (ele_param, style_param) {
        if (! +"\v1") {
            ele_param.style.cssText = style_param;
        }
        else {
            ele_param.setAttribute("style", style_param);
        }
    };

    /**
    *
    * @name lib.dom.getAStyle
    * @function
    * @grammar lib.dom.getAStyle(ele,name)
    * @param {object} ele    :a dom element
    * @param {string} name    :the name of the css
    * @meta standard
    * @return {string} the value of css[name];
    */

    lib.dom.getAStyle = function (ele, name) {
        if (elem.style[name]) {
            return elem.style[name];
        }
        else if (elem.currentStyle) { //IE 和Opera浏览器会进入这项
            return elem.currentStyle[name];
        }
        else if (document.defaultView && document.defaultView.getComputedStyle) {
            name = name.replace(/([A-Z])/g, "-$1").toLowerCase(); // 如： textAlign替换成text-align
            var s = document.defaultView.getComputedStyle(elem, "");
            return s && s.getPropertyValue(name);
        }
        else { return null; }
    };

    // 获取元素宽度
    lib.dom.getOffsetWidth = function(content) {
        var span = document.createElement('SPAN');
        span.style.visibility="hidden";
        span.style.fontSize = '14px';
        span.style.paddingLeft = '6px'
        span.style.paddingRight = '6px'
        span.innerText = content;
        document.body.appendChild(span);
        var width = span.offsetWidth;
        document.body.removeChild(span);
        return width;
    }

    /**
    *
    * name lib.dom.createTable
    *
    *
    *
    */

    lib.dom.createTable = function (paraArray, paraID) {
        var tmpTable = $CE("table");
        tmpTable.id = paraID;
        var tmpTbody;
        var tmpCurrentNode;
        if (! +"\v1") {   // If the broswer is IE, add a "TBODY" element to the table.
            tmpTbody = $CE("TBODY");
            tmpTable.appendChild(tmpTbody);
            tmpCurrentNode = tmpTbody;
        }
        else {
            tmpCurrentNode = tmpTable;
        }
        for (var i in paraArray) {
            var tmpTr = $CE("TR");
            var tmpFirstTd = $CE("TD");
            var tmpKey;
            for (var tmp in paraArray[i]) {
                tmpKey = tmp.toString();
                break;
            }
            tmpFirstTd.innerHTML = tmpKey;
            tmpTr.appendChild(tmpFirstTd);
            var tmpSecondTd = $CE("TD");
            for (var j in paraArray[i][tmpKey]) {
                var tmpA = $CE("A");
                tmpA.innerHTML = paraArray[i][tmpKey][j];
                tmpSecondTd.appendChild(tmpA);
            }
            tmpTr.appendChild(tmpSecondTd);
            tmpCurrentNode.appendChild(tmpTr);
        }
        return tmpTable;
    };

    lib.dom.disAtCenter = function (ele) {
        //计算顶部位置值
        var winH;
        if (window.innerHeight) { // all except IE
            winH = window.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) {
            // IE 6 Strict Mode
            winH = document.documentElement.clientHeight;
        } else if (document.body) { // other
            winH = document.body.clientHeight;
        }
        var top = parseInt(parseInt(winH * 0.25) + (document.body.scrollTop || document.documentElement.scrollTop));
        ele.style.position = "absolute";     //设为绝对定位
        //计算左边位置
        var left = Math.ceil(((Math.min(document.body.scrollWidth, window.screen.availWidth)) - parseInt(ele.style.width.replace('px', ''))) / 2) + document.body.scrollLeft;
        ele.style.zIndex = "9";    //Z轴位置
        ele.style.top = top + "px";  //设置顶部边距
        if (!ele.parentNode) {
            document.body.appendChild(ele);
        }
        //放在"document.body.appendChild(ele);"后，这样ele.clientWidth才有具体的值.
        var left = Math.ceil(((Math.min(document.body.scrollWidth, window.screen.availWidth)) - ele.clientWidth) / 2) + document.body.scrollLeft;
        ele.style.left = left + "px";    //设置左边距
    };
    /* 拖曳DOM元素
    * @param   {HTMLElement|ID}    ele 被拖曳的元素
    * @param   {Function}          startHandler 开始拖动时的处理函数
    * @param   {Function}          draggingHandler 拖动时的处理函数
    * @param   {Function}          endHandler 结束拖动时的处理函数
    * @param   {JSON}              options 拖曳配置项
    */
    lib.dom.Drag = function (ele, startHandler, draggingHandler, endHandler) {
        ele = ('object' === typeof ele) ? ele : lib.$(ele);
        ele.onMousemove = draggingHandler;
    };

    /*清除所有子节点
    * @para {Object}   p 父节点，它的子节点将被删除.
    */
    lib["dom"]["clearChildren"] = function (p) {
        if (p == U) return;
        while (p.childNodes.length > 0) {
            p.removeChild(p.firstChild);
        }
    }

    lib.dom.getAbsLeftTop = function (p) {
        var _left = 0, _top = 0;
        if (p.offsetParent) {
            while (1) {
                _left += p.offsetLeft;
                _top += p.offsetTop;
                if (!p.offsetParent) {
                    break;
                } else if (p.offsetParent.style.position == "absolute") {
                    _left += t.offsetParent.offsetLeft;
                    _top += t.offsetParent.offsetTop;
                    break;
                }
                p = p.offsetParent;
            }
        }
        else if (p.x && p.y) {
            _left += p.x;
            _top += p.y;
        }
        return { "left": _left, "top": _top };
    };

    lib["data"] = {}; //a class

    //    lib.data.encrypt = function (str, pwd) {
    //        if (str == "") return "";
    //        str = escape(str);
    //        if (!pwd || pwd == "") { var pwd = "1234"; }
    //        pwd = escape(pwd);
    //        if (pwd == null || pwd.length <= 0) {
    //            alert("Please enter a password with which to encrypt the message.");
    //            return null;
    //        }
    //        var prand = "";
    //        for (var I = 0; I < pwd.length; I++) {
    //            prand += pwd.charCodeAt(I).toString();
    //        }
    //        var sPos = Math.floor(prand.length / 5);
    //        var mult = parseInt(prand.charAt(sPos) + prand.charAt(sPos * 2) + prand.charAt(sPos * 3) + prand.charAt(sPos * 4) + prand.charAt(sPos * 5));

    //        var incr = Math.ceil(pwd.length / 2);
    //        var modu = Math.pow(2, 31) - 1;
    //        if (mult < 2) {
    //            alert("Algorithm cannot find a suitable hash. Please choose a different password. \nPossible considerations are to choose a more complex or longer password.");
    //            return null;
    //        }
    //        var salt = Math.round(Math.random() * 1000000000) % 100000000;
    //        prand += salt;
    //        while (prand.length > 10) {
    //            prand = (parseInt(prand.substring(0, 10)) + parseInt(prand.substring(10, prand.length))).toString();
    //        }
    //        prand = (mult * prand + incr) % modu;
    //        var enc_chr = "";
    //        var enc_str = "";
    //        for (var I = 0; I < str.length; I++) {
    //            enc_chr = parseInt(str.charCodeAt(I) ^ Math.floor((prand / modu) * 255));
    //            if (enc_chr < 16) {
    //                enc_str += "0" + enc_chr.toString(16);
    //            } else
    //                enc_str += enc_chr.toString(16);
    //            prand = (mult * prand + incr) % modu;
    //        }
    //        salt = salt.toString(16);
    //        while (salt.length < 8) salt = "0" + salt;
    //        enc_str += salt;
    //        return enc_str;
    //    };

    //    lib.data.decrypt = function (str, pwd) {
    //        if (str == "") return "";
    //        if (!pwd || pwd == "") { var pwd = "1234"; }
    //        pwd = escape(pwd);
    //        if (str == null || str.length < 8) {
    //            alert("A salt value could not be extracted from the encrypted message because it's length is too short. The message cannot be decrypted.");
    //            return;
    //        }
    //        if (pwd == null || pwd.length <= 0) {
    //            alert("Please enter a password with which to decrypt the message.");
    //            return;
    //        }
    //        var prand = "";
    //        for (var I = 0; I < pwd.length; I++) {
    //            prand += pwd.charCodeAt(I).toString();
    //        }
    //        var sPos = Math.floor(prand.length / 5);
    //        var mult = parseInt(prand.charAt(sPos) + prand.charAt(sPos * 2) + prand.charAt(sPos * 3) + prand.charAt(sPos * 4) + prand.charAt(sPos * 5));
    //        var incr = Math.round(pwd.length / 2);
    //        var modu = Math.pow(2, 31) - 1;
    //        var salt = parseInt(str.substring(str.length - 8, str.length), 16);
    //        str = str.substring(0, str.length - 8);
    //        prand += salt;
    //        while (prand.length > 10) {
    //            prand = (parseInt(prand.substring(0, 10)) + parseInt(prand.substring(10, prand.length))).toString();
    //        }
    //        prand = (mult * prand + incr) % modu;
    //        var enc_chr = "";
    //        var enc_str = "";
    //        for (var I = 0; I < str.length; I += 2) {
    //            enc_chr = parseInt(parseInt(str.substring(I, I + 2), 16) ^ Math.floor((prand / modu) * 255));
    //            enc_str += String.fromCharCode(enc_chr);
    //            prand = (mult * prand + incr) % modu;
    //        }
    //        return unescape(enc_str);
    //    };
    /*获取数据中的键值
    * @param   {String}  input 数据
    * @param   {String} key 键
    */
    lib.data.getValueFromContent = function (input, key) {
        var i = input.indexOf(key);
        if (input.substring(i + key.length, i + key.length + 1) == "=") {
            var j = input.indexOf(";", i);
            if (j != -1) {
                return input.substring(i + key.length + 1, j);
            }
            else {
                return input.substring(i + key.length + 1, input.length);
            }
        }
    };


    /*获取元素在数组中的序号
    * @param   {Array}  _paraArray 数组
    * @param   {Object}  _paraEle 元素
    */
    lib.data.getOrder = function (_paraArray, _paraEle) {
        for (var i = 0; i < _paraArray.length; i++) {
            if (_paraArray[i] === _paraEle) {
                return i;
            }
        }
        return -1;
    }

    /*获取字符串的字节数
    * @para {String} _paraStr 字符串
    * @return {Number}字符串的字节数
    */
    lib.data.getStrLength = function (_paraStr) {
        if (_paraStr == null) return 0;
        return _paraStr.replace(/[^x00-xff]/g, "aa").length;
    };

    lib.data.getObByAttribute = function (_array, _att, _v) {
        for (var i = 0; i < _array.length; i++) {
            if (_array[i][_att] == _v) {
                return _array[i];
            }
        }
    };

    /*
    * 判断source中是否含有keyword字符串
    */
    lib.data.isLike = function (keyword, source) {
        if (undefined == keyword || undefined == source) {
            return false;
        }
        var keyword = keyword.toString().toLowerCase();
        var source = source.toString().toLowerCase();
        if (source.indexOf(keyword) > -1) {
            return true;
        }
        return false;
    }

    function ajax(option) {

        //     debugger;
        //            try {
        //                xmlRequest.open("POST", url, true);
        //                xmlRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        //                xmlRequest.setRequestHeader("Connection", "close");
        //                xmlRequest.onreadystatechange = function () {
        //                    if (xmlRequest.readyState == 4 && xmlRequest.status == 200) {
        //                        func(xmlRequest.responseText);
        //                    } else {
        //                        xmlRequest.send(data);
        //                        // 重新加载
        //                    }
        //                };
        //                xmlRequest.send(data);
        //            } catch (e) {
        //                return false;
        //            }
        //        }




        try {


            xmlRequest.open(option.type, option.url, option.async, option.username, option.password);
            xmlRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            if (navigator.userAgent.indexOf("MSIE") > 0) {
                xmlRequest.setRequestHeader("Connection", "close");
            }
            // Open the socket
            // Passing null username, generates a login popup on Opera (#2865)
            //            

            xmlRequest.onreadystatechange = function () {
                if (xmlRequest.readyState == 4 && xmlRequest.status == 200) {
                    option.success(xmlRequest.responseText);
                }
                else {

                    //                    xmlRequest.send(option.data);
                    // 重新加载
                }
            };
            //            if (option.type.toUpperCase() === "POST") {
            //                xmlRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            //            }
            xmlRequest.send(option.data || null);
        } catch (ex) {
            option.error(xmlRequest, ex.message, ex);
        }
    }
    lib.ajax = ajax;

    lib.tools = {};
    lib.tools.drawRuler = function(data, ele) {
        var ctx = ele.getContext('2d')
        ctx.lineWidth = 0.5;
        var start = { x: 20, y: ele.offsetHeight / 2 };
        ctx.moveTo(start.x, start.y + 10);
        ctx.lineTo(start.x, start.y - 10);
        ctx.moveTo(start.x, start.y);

        var nextX = start.x;
        for (var i = 0, len = data.length; i < len; i++) {
            nextX += data[i];
            ctx.lineTo(nextX, start.y);
            ctx.moveTo(nextX, start.y + 10);
            ctx.lineTo(nextX, start.y - 10);
            ctx.moveTo(nextX, start.y);
        }
        ctx.stroke();
    }

    lib["debug"] = {}; //a clss
    lib.debug.log = function (_txt) {
        g.ComWithServer.add(g.domainDirectory + "/log.aspx", (new Date).toTimeString() + ": " + _txt);
        g.ComWithServer.startSend();

    };
    lib["browser"] = lib["browser"] || function () {//还有几个浏览器中的language没有设置
        var ua = navigator.userAgent;
        var result = {
            isStrict: document.compatMode == "CSS1Compat",
            isMobile: !!ua.match(/AppleWebKit.*Mobile.*/)//是否为移动终端
            , isGecko: /gecko/i.test(ua) && !/like gecko/i.test(ua)
            , isWebkit: /webkit/i.test(ua)
        };
        try {
            if (/(\d+\.\d+)/.test(external.max_version)) {
                result.maxthon += RegExp['\x241'];
            }
        }
        catch (e) { };
        // 蛋疼 你懂的     
        switch (true) {
            case /msie (\d+\.\d+)/i.test(ua):
                result.ie = document.documentMode || +RegExp['\x241'];
                result.language = navigator.browserLanguage;
                break;
            case /chrome\/(\d+\.\d+)/i.test(ua):
                result.chrome = +RegExp['\x241'];
                result.language = navigator.language;
                break;
            case /(\d+\.\d)?(?:\.\d)?\s+safari\/?(\d+\.\d+)?/i.test(ua) && !/chrome/i.test(ua):
                result.safari = +(RegExp['\x241'] || RegExp['\x242']);
                result.language = navigator.language;
                break;
            case /firefox\/(\d+\.\d+)/i.test(ua):
                result.firefox = +RegExp['\x241'];
                result.language = navigator.language;
                break;
            case /opera(\/| )(\d+(\.\d+)?)(.+?(version\/(\d+(\.\d+)?)))?/i.test(ua):
                result.opera = +(RegExp["\x246"] || RegExp["\x242"]);
                result.language = navigator.language;
                break;
        }
        //baidu.extend(baidu, result);
        return result;
    }();
    //baidu.browser.firefox = /firefox\/(\d+\.\d+)/i.test(navigator.userAgent) ? + RegExp['\x241'] : undefined


    /*在文本框中显示历史.
    * @para {String}   message 要增加的文本信息.
    */
    lib.debug.displayHistory = function (message) {
        var element = lib.$("history"); //现在默认存在ID为"history"的文本框元素.
        element.value += (new Date).getTime().toString() + " : " + message + "\n";
        if (element.value.length > 1000) {
            element.value = element.value.substring(element.value.length - 1000, element.value.length);
        }
        element.scrollTop = element.scrollHeight;
    };

    lib.debug.log = function (_txt) {
        g.ComWithServer.add(g.domainDirectory + "/log.aspx", (new Date).toTimeString() + ": " + _txt);
        g.ComWithServer.startSend();

    };

    lib.web = {};
    lib.web.search = function (_para) { //搜索
        var tmpKeyword = $("webKeywordID").value;
        var a = 0;
    }

    lib.web.importDataToTable = function (_paraXMLOrJSONData) {//将xml或json数据导入g.WebTable["First"]
        //        if() {//

        //        }
        //        else {


        //        }

    }



    //lib.getXMLByKeyword = function ( sourceXML:string, keyword:string, priority:string[] )



    /**
    * 
    * 
    * test
    * 
    */
    var myTest = lib.dom.createTable([{ "jack": ["one", "two"] }, { "john": ["A", "B"] }], "ID1");

    /**
    test
    */
    window.g = {};
    window.g.WebActive = {}; //the web operated just now
    window.g.Web = {};
    window.g.elementDragClass = {}; // the data structure of the webs dragged.
    window.g.eleThreeDomHashtable = {};
    window.g.tableRowWeb = {};
    window.g.mouseEvent = {};
    window.g.mouseoverWebEleDiv = {};
    window.g.volatileArray = {};
    window.g.selectedData = {};
    window.g.WebTable = {};
    window.g.Category = {};

    //+------------------get the version of the browse-----------------
    window.Sys = {};
    var ua = navigator.userAgent.toLowerCase();
    var s;
    (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
        (s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
            (s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
                (s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
                    (s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;
    //if(Sys.ie)或if(Sys.firefox)等形式，而判断浏览器版本只需用if(Sys.ie == '8.0')或if(Sys.firefox == '3.0')等形式，表达起来还是非常优雅的。
    window.Sys.isMiniScreen = Sys.isMiniScreen || function () { return (Math.min(window.screen.height, window.screen.width) < 600); }();
})();

/**
var Module;
//check Module --> make sure 'Module' is not existed
if (!!Module && (typeof Module != 'object' || Module.NAME)) throw new Error("NameSpace 'Module' already Exists!");

Module = {};

Module.NAME = 'Module';
Module.VERSION = 0.1;

Module.EXPORT = ['require',
'importSymbols'];

Module.EXPORT_OK = ['createNamespace',
'isDefined',
'modules',
'globalNamespace'];

Module.globalNamespace = this;

Module.modules = {'Module': Module};

// create namespace --> return a top namespace
Module.createNamespace = function (name, version) {
if (!name) throw new Error('name required');
if (name.charAt(0) == '.' || name.charAt(name.length-1) == '.' || name.indexOf('..') != -1) throw new Error('illegal name');

var parts = name.split('.');

var container = Module.globalNamespace;
for (var i=0; i<parts.length; i++) {
var part = parts[i];
if (!container[part]) container[part] = {};
container = container[part];
}

var namespace = container;
if (namespace.NAME) throw new Error('module "'+name+'" is already defined');
namespace.NAME = name;
if (version) namespace.VERSION = version;

Module.modules[name] = namespace;
return namespace;
};
// check name is defined or not
Module.isDefined = function (name) {
return name in Module.modules;
};
// check version
Module.require = function (name, version) {
if (!(name in Module.modules)) throw new Error('Module '+name+' is not defined');
if (!version) return;

var n = Module.modules[name];
if (!n.VERSION || n.VERSION < version) throw new Error('version '+version+' or greater is required');
};
// import module
Module.importSymbols = function (from) {
if (typeof form == 'string') from = Module.modules[from];
var to = Module.globalNamespace; //dafault
var symbols = [];
var firstsymbol = 1;

if (arguments.length > 1 && typeof arguments[1] == 'object' && arguments[1] != null) {
to = arguments[1];
firstsymbol = 2;
}

for (var a = firstsymbol; a < arguments.length; a++) {
symbols.push(arguments[a]);
}

if (symbols.length == 0) {
//default export list
if (from.EXPORT) {
for (var i = 0; i < from.EXPORT.length; i++) {
var s = from.EXPORT[i];
to[s] = from[s];
}
return;
} else if (!from.EXPORT_OK) {
// EXPORT array && EXPORT_OK array both undefined
for (var s in from) {
to[s] = from[s];
return;
}
}
}

if (symbols.length > 0) {
var allowed;
if (from.EXPORT || form.EXPORT_OK) {
allowed = {};
if (from.EXPORT) {
for (var i = 0; i < form.EXPORT.length; i++) {
allowed[from.EXPORT[i]] = true;
}
}
if (from.EXPORT_OK) {
for (var i = 0; i < form.EXPORT_OK.length; i++) {
allowed[form.EXPORT_OK[i]] = true;
}
}
}

}
//import the symbols
for (var i = 0; i < symbols.length; i++) {
var s = symbols[i];
if (!(s in from)) throw new Error('symbol ' + s + ' is not defined');
if (!!allowed && !(s in allowed)) throw new Error(s + ' is not public, cannot be imported');
to[s] = form[s];
}
};

Module.EXPORT_OK = ['createNamespace',
'isDefined',
'modules',
'globalNamespace'];

Module.globalNamespace = this;

Module.modules = { 'Module': Module };

// check name is defined or not
Module.isDefined = function (name) {
return name in Module.modules;
};
//check version
Module.require = function (name, version) {
if (!(name in Module.modules)) throw new Error('Module '+name+' is not defined');
if (!version) return;

var n = Module.modules[name];
if (!n.VERSION || n.VERSION < version) throw new Error('version '+version+' or greater is required');
};

// import module
Module.importSymbols = function (from) {
if (typeof form == 'string') from = Module.modules[from];
var to = Module.globalNamespace; //dafault
var symbols = [];
var firstsymbol = 1;

if (arguments.length>1 && typeof arguments[1] == 'object' && arguments[1] != null) {
to = arguments[1];
firstsymbol = 2;
}

for (var a=firstsymbol; a<arguments.length; a++) {
symbols.push(arguments[a]);
}

if (symbols.length == 0) {
//default export list
if (from.EXPORT) {
for (var i=0; i<from.EXPORT.length; i++) {
var s = from.EXPORT[i];
to[s] = from[s];
}
return;
} else if (!from.EXPORT_OK) {
// EXPORT array && EXPORT_OK array both undefined
for (var s in from) {
to[s] = from[s];
return;
}
}
}

if (symbols.length > 0) {
var allowed;
if (from.EXPORT || form.EXPORT_OK) {
allowed = {};
if (from.EXPORT) {
for (var i=0; i<form.EXPORT.length; i++) {
allowed[from.EXPORT[i]] = true;
}
}
if (from.EXPORT_OK) {
for (var i=0; i<form.EXPORT_OK.length; i++) {
allowed[form.EXPORT_OK[i]] = true;
}
}
}

}
//import the symbols
for (var i=0; i<symbols.length; i++) {
var s = symbols[i];
if (!(s in from)) throw new Error('symbol '+s+' is not defined');
if (!!allowed && !(s in allowed)) throw new Error(s+' is not public, cannot be imported');
to[s] = form[s];
}
}

Module.createNamespace('Hongru');
Module.createNamespace('me', 0.1);
me.EXPORT = ['define'];
me.define = function () {
this.NAME = '__me';
};
Module.importSymbols(me, Hongru);//把me名字空间下的标记导入到Hongru名字空间下


*/
